import requests, re
from bs4 import BeautifulSoup
from common.consts import SPIDER_HEADER
def spider_fans_id_list(id, page):
    # 格式 date = 2024-01-01
    url = f'https://weibo.cn/{id}/fans'
    params = {
        'page': page,
        'mp': 20
    }
    reponse = requests.post(url, headers=SPIDER_HEADER, params=params)
    soup = BeautifulSoup(reponse.text, 'html.parser')
    
    div_list = soup.find_all('div', class_='c')
    id_list = []
    for div in div_list:
        table_list = div.find_all('table')
        for table in table_list:
            element = table.find_all('a')
            if not element:
                continue
            current_id = element[0].get('href').split('/')[-1]
            # 如果这个字符串不为数字
            if not current_id.isdigit():
                link = element[2].get('href')
                current_id = re.search(r'uid=(\d+)', link)[1]
            id_list.append(current_id)
    return id_list
